import { http } from '@/request/http'
import type { PageDTO, PageVO } from '@/type/type'

export type TreeHole = {
  // 自增主键
  id: number
  // 发送人ip地址
  ip: string
  // 随机头像
  avatar: string
  // 留言内容
  content: string
  // 点赞
  likeCount: number
  // 创建时间
  createTime: Date
}

export type TreeHoleDTO = {
  // 留言内容
  content: string
}

export const getTreeHolePageApi = (page: PageDTO) => {
  return http<PageVO<TreeHole>>({
    url: `/tree_hole/page`,
    method: 'get',
    params: {
      dto: JSON.stringify(page)
    }
  })
}

export const getTreeHoleAdminPageApi = (page: PageDTO) => {
  return http<PageVO<TreeHole>>({
    url: `/admin/tree_hole/page`,
    method: 'get',
    params: {
      dto: JSON.stringify(page)
    }
  })
}

export function addTreeHoleApi(treeHole: TreeHoleDTO) {
  return http<boolean>({
    url: '/tree_hole/insert',
    method: 'POST',
    data: treeHole
  })
}

export function delTreeHoleApi(ids: number[]) {
  return http<boolean>({
    url: `/admin/tree_hole/delete`,
    method: 'delete',
    data: ids
  })
}
